import org.kwis.msp.lcdui.Jlet;
import org.kwis.msp.lcdui.Display;

import org.kwis.msp.lwc.Component;
import org.kwis.msp.lwc.ContainerComponent;
import org.kwis.msp.lwc.ShellComponent   ;
import org.kwis.msp.lwc.ButtonComponent   ;

public class ContainerComponentEx2 extends Jlet{

	class ExtendedContainer extends ContainerComponent{

		int dxInset , dyInset;

		public ExtendedContainer(){
			super();
		}

		public ExtendedContainer(int x , int y){
			super();
			dxInset=x;
			dyInset=y;
		}

		

		protected void layout(){
			
			int numComponent = getNumberOfComponent();
			int height = getHeight()-(insetTop+insetBottom);
			int width = getWidth()-(insetLeft+insetRight);
			int widthComponent = width / numComponent;
			int heightComponent = height / numComponent;

			for(int i=0;i<numComponent;i++) {
				Component c = getComponent(i);
				c.configure(insetLeft,insetTop+2*i*(heightComponent/2),width,(heightComponent/2), POS_MASK | SIZE_MASK);
			}
		}
		
		protected void controlInset(boolean b) {
				insetTop = (short)dyInset;
				insetLeft = (short)dxInset;
				insetBottom =(short)dyInset;
				insetRight = (short)dxInset;
		}
		
	}


	Display displayLCD ;
	ShellComponent shell;	

	public ContainerComponentEx2(){  	}

	protected void startApp(String[] arg0){
		
		displayLCD = Display.getDefaultDisplay();
		shell = new ShellComponent();
		 //shell = new ShellComponent(false, false);
		ButtonComponent button1 = new ButtonComponent("Button1",null);
		ButtonComponent button2 = new ButtonComponent("Button2",null);
		ButtonComponent button3 = new ButtonComponent("Button3",null);

		ExtendedContainer container = new ExtendedContainer(10,10);

		container.addComponent(button1);
		container.addComponent(button2);
		container.addComponent(button3);

		container.useFrame( true );

		shell.setTitle("  Container Layout");
		shell.setWorkComponent(container);
		displayLCD.pushCard(shell.getCard());
	
	}
	protected void destroyApp(boolean arg0) {  }


}
